<?php
session_start();
//session_register('login_state');
//$_SESSION['login_state'] ;
//===========================================================
$path = '../';
include($path."common.php");
include($path."prod_fun.php");
//=========================================================== 
$pageout = "ord_login.php" ; 
//echo $login_state ;
if($_SESSION['login_state'] <> "S" and $_SESSION['login_state'] <> "O"){
	gotopage($pageout) ;
}
?>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../css/cart.css" />
<script language="javascript">
var xmlHttp;
function createXHR(){
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (!xmlHttp) {
		alert('您使用的瀏覽器不支援 XMLHTTP 物件');
		return false;
	}
}

function sendRequest(url){
	createXHR() ;
	xmlHttp.open('GET',url,true) ;
	xmlHttp.onreadystatechange = catchXML ;
	xmlHttp.send(null) ;
}

function catchXML(){
	if (xmlHttp.readyState==4){
		xml=xmlHttp.responseXML;
		if (xmlHttp.status == 200) {
//            document.getElementById('s').innerHTML=xmlHttp.responseText ;
			location.reload() ;
		}else{
			alert('執行錯誤,代碼:'+xmlHttp.status+'\('+xmlHttp.statusText+'\)');
		}
	}
}

</script>
<?



$sql = "select * from kart_order order by order_id " ;
$result = mysql_query($sql);

$site = "ord_list.php" ;
$pagesize = 10; //每頁筆數
$numrows = mysql_num_rows($result) ; //總筆數
$totalpages = ceil($numrows / $pagesize); //頁數、最後一頁頁碼
if(!isset($_GET["page"])){
$currentpage = 1 ;
}else{
$currentpage = $_GET['page'] ;
}
$startnum = ($currentpage -1) * $pagesize;   //開始的筆數
$startnum = $startnum < 0 ? 0 : $startnum;


//===========================================================
echo "<form method=post id=list_item name=frm_list action=\"ord_act.php?nowpage=$currentpage\">" ;
echo "<table width=800 border=1 align=center>" ;
echo "<tr><td colspan=5 align=center><h3> </h3><input class=sumbit name=action type=submit value='登出'></td></tr>" ;
echo "<tr>" ;
echo "<td width=12% align=center class=blue>訂單編號</td>" ;
echo "<td width=12% align=center class=Sky>訂單金額</td>" ;
echo "<td width=12% align=center class=blue>訂單日期</td>" ;
echo "<td width=12% align=center class=Sky>交易狀態</td>" ;
echo "<td width=12% align=center class=blue>查詢細項</td>" ;
echo "</tr>" ;
//===========================================================
$act_inq = urlencode("查詢資料") ;

$sql_list = "select * from kart_order order by order_id limit $startnum,$pagesize" ;
$result_list = mysql_query($sql_list);
while($row_list=mysql_fetch_object($result_list)){
$ordno = $row_list->order_id ;
$price = $row_list->order_price ;
$ord_d = $row_list->order_date ;
$ord_t = $row_list->order_time ;
$ord_s = $row_list->order_state ;

//===========================================================
//時間
$ord_dt = substr($ord_d,0,4) . "-" .  substr($ord_d,4,2) . "-"  . substr($ord_d,6,2) . "&nbsp;&nbsp;" .  substr($ord_t,0,2) . ":" .  substr($ord_t,2,2) . ":"  . substr($ord_t,4,2)  ;
//交易狀態
switch($ord_s){
case "S" :
$state = "已付費，已確認送貨" ;    
break;
case "Y" :
$state = "已付費，尚未送貨" ;    
break;
case "N" :
$state = "尚未付費" ;    
break;
}
//===========================================================
echo "<tr height=20>" ;
echo "<td align=center>".$ordno."</td>" ;
echo "<td>"."NT$ ".$price."</td>" ;
echo "<td align=center>".$ord_dt."</td>" ;
echo "<td align=center>".$state."</td>" ;
echo "<td align=center>"."<input class=search name=action type=button value='查詢' onclick=\"location.href='ord_act.php?oid=$ordno&action=$act_inq&oid=$ordno&nowpage=$currentpage'\">"."</td>" ;
echo "</tr>" ;
}
//===========================================================
echo "</table>" ;
echo "</form>" ;
//===========================================================
echo "<table width=800 border=0 align=center>" ;
echo "<tr><td align=center>" ;
fenye($site,$currentpage,$totalpages) ;
echo "</td></tr>" ;
echo "</table>" ;
//===========================================================
?>